import './js/weapp-adapter'
const ctx = canvas.getContext('2d');
//导入背景绘制模块
import Background from './js/Background.js';
var bg = new Background(ctx);
//导入母鸡绘制模块
import Chicken from './js/Chicken.js';
var chicken = new Chicken(ctx);
//导入篮子绘制模块
import Basket from './js/Basket.js';
var basket = new Basket(ctx);
//启动篮子移动事件的监听
basket.listen();

//导入鸡蛋绘制模块
import Egg from './js/Egg.js';
var egg = new Egg(ctx);
//导入鸡蛋碎掉绘制模块
import Boom from './js/Boom.js';
var boom = new Boom(ctx,egg);

//导入批量操作
import Pool from './js/Pool.js';
var pool = new Pool(ctx, basket, egg, music);
//导入绘制分数模块
import Info from './js/Info.js';
var info = new Info(ctx);
//导入背景音乐模块
import Music from './js/Music.js';
var music = new Music();


//动画效果控制
function gameStart() {
//控制背景效果
music.bgPaly();
bg.draw();
//绘制母鸡
chicken.draw();
//绘制篮子
basket.draw()
//批量绘制鸡蛋
pool.draweggs(bg.top,basket);
//批量绘制鸡蛋碎掉的效果
pool.drawBooms();
//绘制分数
info.showScore(pool.score);

if (pool.isOver === true) {
  music.bgPaly();
  wx.showModal({
    title: '游戏结束!',
    content: '想要再来一局吗？',
    showCancel: true,
    cancelText: '否',
    confirmText: '是',
    success: (res) => {
      if (res.confirm) {
        console.log('用户点击是');
        basket = new Basket(ctx);
        egg = new Egg(ctx);
        boom = new Boom(ctx, egg);
        pool = new Pool(ctx, basket, egg, music);
        info = new Info(ctx);
        //启动篮子移动事件的监听
        basket.listen();
        //启动动画
        requestAnimationFrame(gameStart);
      } else if (res.cancel) {
        console.log('用户点击否');
      }
    },
    fail: (res) => { console.log('用户点击是'); },
    complete: (res) => { console.log('用户点击否'); },
  });
    return;//终止动画
}

//启动动画
requestAnimationFrame(gameStart);
}
gameStart();